package com.lhy.vip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lhy.vip.domain.Integral;
import com.lhy.vip.service.IntegralService;
import com.lhy.vip.mapper.IntegralMapper;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


import java.util.List;

/**
* @author lhy
* @description 针对表【integral】的数据库操作Service实现
* @createDate 2024-07-29 16:50:07
*/
@Service
public class IntegralServiceImpl implements IntegralService{
    @Autowired
    private IntegralMapper iIntegralMapper;

    @Override
    public List<Integral> selectAll() {
        LambdaQueryWrapper <Integral> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Integral::getIsDelete,0);
        return iIntegralMapper.selectList(lqw);
    }


    @Override
    public List<Integral> selectList(Integral iIntegral) {
        LambdaQueryWrapper <Integral> lqw = this.lqw(iIntegral);
        return iIntegralMapper.selectList(lqw);
    }

    @Override
    public Integer insert(Integral iIntegral) {
        return iIntegralMapper.insert(iIntegral);
    }

    @Override
    @Transactional
    public Integer delete(String ids) {
        try {
            String[] split = ids.split(",");
            for (String id : split) {
                Integral iIntegral = new Integral();
                iIntegral.setId(Long.parseLong(id));
                iIntegral.setIsDelete(1);
                iIntegralMapper.updateById(iIntegral);
            }
            return 1;
        }catch (Exception e){
            return -1;
        }
    }

    @Override
    public Integer update(Integral iIntegral) {
        return iIntegralMapper.updateById(iIntegral);
    }

    @Override
    public Page<Integral> pageAll(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<Integral>)this.selectAll();
    }

    @Override
    public Page<Integral> pageList(Integral iIntegral, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<Integral>)this.selectList(iIntegral);
    }

    public LambdaQueryWrapper lqw(Integral iIntegral){
        LambdaQueryWrapper <Integral> lqw = new LambdaQueryWrapper<>();
        if (iIntegral.getId() != null){
            lqw.eq(Integral::getId,iIntegral.getId());
        }
        if (iIntegral.getVipName() != null){
            lqw.eq(Integral::getVipName,iIntegral.getVipName());
        }
        if (iIntegral.getContent() != null){
            lqw.eq(Integral::getContent,iIntegral.getContent());
        }
        if (iIntegral.getBefore() != null){
            lqw.eq(Integral::getBefore,iIntegral.getBefore());
        }
        if (iIntegral.getChange() != null){
            lqw.eq(Integral::getChange,iIntegral.getChange());
        }
        if (iIntegral.getAfter() != null){
            lqw.eq(Integral::getAfter,iIntegral.getAfter());
        }
        if (iIntegral.getCreateTime() != null){
            lqw.eq(Integral::getCreateTime,iIntegral.getCreateTime());
        }
        return lqw;
    }
}




